using System;
using Microsoft.SPOT;

namespace Microsoft.NETMF.BikeComputer.Application
{
    class ElapsedTimer
    {
        private TimeSpan _elapsedTime;
        private DateTime _startTime;
        private bool _timing;


        public ElapsedTimer()
        {
            _elapsedTime = new TimeSpan (0);
            _startTime =    new DateTime(0);
            _timing = false;
        }

        public void StartElapsedTimer()
        {
            _startTime = DateTime.Now;
            _timing = true;
        }

        public void StopElapsedTimer()
        {
            _elapsedTime += (DateTime.Now - _startTime);
            _timing = false;
        }

        public TimeSpan GetElapsedTime()
        {
            if (_timing)
            {
                return _elapsedTime + (DateTime.Now - _startTime);
            }
            else
            {
                return _elapsedTime;
            }
        }

        public String GetElapsedTimeString()
        {

            TimeSpan _et;

            if (_timing)
            {
                _et = _elapsedTime + (DateTime.Now - _startTime);
            }
            else
            {
                _et = _elapsedTime;
            }

            return (_et.Hours.ToString() + ":" + _et.Minutes.ToString() + ":" + _et.Seconds.ToString());
        }

    }


}
